function Get_Wxyun(id){
     $("#Up_LoginQrcode").html(''); //清空登陆码
     ZT_WXYUN_ID = 'XFPAY';
     ZT_QrCode_URL = 0; //判断是否已经获取到二维码
     Up_QrCode_cookie = 0; //判断是否已经获取COOKIE
     var ii = layer.load(5, {
        shade: [0.1, '#fff']
    });
    $.ajax({
        type: "POST",
        url: "Ajax.php",
        data:{
            act:'Get_Qr',
            id:id
        },
        dataType: 'json',
        timeout: 15000,
        success: function(res) {
            layer.close(ii);
            if(res.code !== 200){
	            layer.msg(res.msg, {
                    icon: 2,
                    time: 3000
                }, function() {
                    location.reload();
                });
                return false;
	        }
            if (res.data.id){
                $(function(){
                    setTimeout(function(){
                        var buy = document.getElementById('Up_Qr_modal');
                        buy.click();
                    },200);
                });
                $("#Up_LoginQrcode_msg").html('<center>正在提交获取二维码请求...</center>'); //输出提示
                var is_type = '微信';
                $("#Up_id").val(res.data.id);
                Up_id = res.data.id;
                type = res.data.type; //类型
                beizhu = res.data.beizhu; //备注
                ZT_WXYUN_ID = 0;
                WXYUN_setInterval();
            }
        },
        error: function(data) {
	        layer.close(ii);
	        layer.msg('服务器错误！', {
                icon: 2,
                time: 3000
            });
	    }
    });
      
}

function WXPAY_setInterval(){
    if (ZT_WXYUN_ID == 0){
        var ii = layer.load(5, {
            shade: [0.1, '#fff']
        });
        $.post("Ajax.php",{
            act:'Get_Login_wxQrCode',
            id: Up_id,
        },function(res){
            layer.close(ii);
            if (res.code == 200){
                ZT_QrCode_GUID = res.data.guid;
                ZT_QrCode_UUID = res.data.uuid;
                ZT_QrCode_URL = res.data.qr_url;
                ZT_WXYUN_ID = 1;
                
                var is_type = '"微信"手机摄像头扫一扫,<small style="color:red; font-size:16px">登录选择'+res.data.jixin+'，如果以上没有'+res.data.jixin+'则选择以上都不是</small>';
                $("#Up_LoginQrcode_msg").html('<center>请您使用' + is_type + '->"2分钟内"扫以下码登录,扫码之后请返回此页面等待1分钟,如超过1分钟则系统登录失败,请您再次重试</center>');
                $("#Up_LoginQrcode").html('<center><img align="center" id="qrcodeimg" alt="加载中..." src="' +ZT_QrCode_URL + '" title="扫码登录" width="200" height="200" style=" position: relative; border: green solid 1px;"></center>'); //输出登录二维码
            }else{
                layer.msg(res.msg, {
                        icon: 2,
                        time: 3000
                    }, function() {
                        location.reload();
                    });
            }
        },"JSON");
    }
    if (ZT_WXYUN_ID != 0 && Up_QrCode_cookie == 0) {
        $.post("Ajax.php",{
            act:"Get_Login_wxCookie",
            guid: ZT_QrCode_GUID,
            uuid: ZT_QrCode_UUID,
            type: type,
            qr_id: Up_id,
        },function(res){
            if (res.code == 200){
                Up_QrCode_cookie = res.data.cookie;
                layer.msg('扫码登录成功,正在更新数据...', {
                        icon: 1,
                        time: 2000
                });
                Up_wxQr(Up_QrCode_cookie);
                ZT_WXYUN_ID = 0;
                WXYUN_setInterval(1);
            }else if(res.code == 2){
                $("#Up_LoginQrcode_msg").html('<center>扫码成功，请在手机上点击确认登录...</center>'); //输出提示
                $("#Up_LoginQrcode").html('<center><img align="center" id="qrcodeimg" alt="加载中..." src="/Core/assets/img/pay_ok.png" title="扫码成功" width="200" height="200" style=" position: relative; border: green solid 1px;"></center>'); //输出登录二维码
            }else if (res.code == -1){
                ZT_QrCode_ID = 0;
                ZT_QrCode_URL = 0;
                layer.msg(res.msg, {
                    icon: 2,
                    time: 3000
                }, function() {
                    location.reload();
                });
                WXYUN_setInterval(1);
            }
            
        },"JSON");
    }
}

function Up_wxQr(cookie) {
    var ii = layer.load(5, {
        shade: [0.1, '#fff']
    });
    $.ajax({
        type: "POST",
        url: "Ajax.php",
        data: {
            act:'Up_wxQr',
            id: Up_id,
            cookie:cookie
        },
        dataType: 'json',
        timeout: 15000,
        success: function(data) {
            layer.close(ii);
            layer.msg(data.msg, {
                        icon: 1,
                        time: 2000
            }, function() {
                location.reload();
            });
        },
        error: function(data) {
	        layer.close(ii);
	        layer.msg('服务器错误！', {
                icon: 2,
                time: 3000
            });
	    }
    });
}
function WXYUN_setInterval(type){
    var myVar = setInterval(function(){ WXPAY_setInterval() }, 5000);
    if(type){
        clearInterval(myVar);//判断变量，是否有值，有责停止运行
    } 

}